package com.loiane.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loiane.model.TransformerItem;

@Controller
public class InitController {

	@RequestMapping("/initDprop.do")
	public @ResponseBody String listDpropServers(){

		Map<String,Object> map = new HashMap<String,Object>();
		
		List<TransformerItem> list = new ArrayList<TransformerItem>();
		
		TransformerItem tf0 = new TransformerItem();
		tf0.setId(1);
		tf0.setName("Dprop Serv1");
		list.add(tf0);
		
		TransformerItem tf1 = new TransformerItem();
		tf1.setId(2);
		tf1.setName("Dprop Serv2");
		list.add(tf1);
		
		map.put("success", true);
		map.put("names", list);
		
//		JSONObject jso = JSONObject.fromObject(si);
		JSONObject jso = JSONObject.fromObject(map);
		
		return jso.toString();
	}
	
	@RequestMapping("/initBatchlogserver.do")
	public @ResponseBody String listBatchLogServers(){

		Map<String,Object> map = new HashMap<String,Object>();
		
		List<TransformerItem> list = new ArrayList<TransformerItem>();
		
		TransformerItem tf0 = new TransformerItem();
		tf0.setId(1);
		tf0.setName("Batch Log Serv1");
		list.add(tf0);
		
		TransformerItem tf1 = new TransformerItem();
		tf1.setId(2);
		tf1.setName("Batch Log Serv2");
		list.add(tf1);
		
		map.put("success", true);
		map.put("names", list);
		
		JSONObject jso = JSONObject.fromObject(map);
		
		return jso.toString();
	}

	
	@RequestMapping("/initBatchLog.do")
	public @ResponseBody String listBatchLog(String serverid){
		
		JSONObject jso = null;

		if(null == serverid){
			Map<String,Object> map = new HashMap<String,Object>();
			List<TransformerItem> list = new ArrayList<TransformerItem>();
			map.put("sucuss", false);
			map.put("names", list);
			
			jso = JSONObject.fromObject(map);
			
		}else if("1".equals(serverid)){
			Map<String,Object> map = new HashMap<String,Object>();
			
			List<TransformerItem> list = new ArrayList<TransformerItem>();
			
			TransformerItem tf0 = new TransformerItem();
			tf0.setId(1);
			tf0.setName("Batch Log 1");
			list.add(tf0);
			
			TransformerItem tf1 = new TransformerItem();
			tf1.setId(2);
			tf1.setName("Batch Log 2");
			list.add(tf1);
			
			map.put("success", true);
			map.put("names", list);
			
			jso = JSONObject.fromObject(map);
		}else if("2".equals(serverid)){
			Map<String,Object> map = new HashMap<String,Object>();
			
			List<TransformerItem> list = new ArrayList<TransformerItem>();
			
			TransformerItem tf0 = new TransformerItem();
			tf0.setId(1);
			tf0.setName("Batch Log 3");
			list.add(tf0);
			
			TransformerItem tf1 = new TransformerItem();
			tf1.setId(2);
			tf1.setName("Batch Log 4");
			list.add(tf1);
			
			map.put("success", true);
			map.put("names", list);
			
			jso = JSONObject.fromObject(map);
		}
		
		return jso.toString();
	}
}
